package com.example.design.patterns.geekbang.行为型.策略模式.refactor;

import com.example.design.patterns.geekbang.行为型.策略模式.demo.OrderType;

/**
 * 业务场景需要每次都创建不同的策略对象
 *
 * 策略类有状态
 */
public class DiscountStrategyHaveStateFactory {
    public static DiscountStrategy getDiscountStrategy(OrderType type) {
        if (type == null) {
            throw new IllegalArgumentException("Type should not be null.");
        }
        if (type.equals(OrderType.NORMAL)) {
            return new NormalDiscountStrategy();
        } else if (type.equals(OrderType.GROUPON)) {
            return new GrouponDiscountStrategy();
        } else if (type.equals(OrderType.PROMOTION)) {
            return new PromotionDiscountStrategy();
        }
        return null;
    }
}
